<?php
/**
 * FacebookController class.
 * FacebookController is for facebook API implementation.
 * 
 * LBB Solutions Ltd. 版权所有 @ 2013.
 */
class FacebookController extends ApiController
{
	/**
	 * Post to user time line (wall)
	 */
	public function actionPost()
	{
		$site_token = Yii::app()->request->getParam('site_token');
		if (empty($site_token)) $this->_sendError('Please login with your facebook account!');
		
		$facebook = $this->_getFacebookObject($site_token);
		echo $facebook->getAccessToken();
		
		Yii::app()->end();
		
		$attachment = array(
			'message' => 'this is my message',                    // user's message
			'name' => 'This is my demo Facebook application!',    // the special link name
			'caption' => "Caption of the Post",					  // the link caption below the name (Restaurant A is proving special offer)
			'link' => 'http://yamii.fi',						  // the special link url (to web special link)
			'description' => 'this is a description',			  //the special description
			'picture' => 'http://yamii.fi/img/logo.icon.114.png', //the special picture (90x90)
			/*'actions' => array(
				array(
					'name' => 'Get Search',
					'link' => 'http://www.google.com'
				)
			)*/
		);
		try {
			$result = $facebook->api('/me/feed/', 'post', $attachment);
			$this->_sendJSON(200, $result);
		} catch (FacebookApiException $ex) {
			$this->_sendError($ex->getMessage());
		}
	}
}